package com.bong.ring.fragment;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.bong.ring.R;
import com.bong.ring.activity.common.SearchActivity;
import com.bong.ring.activity.config.ActivityConfigActivity;
import com.bong.ring.activity.config.AutoHeartConfigActivity;
import com.bong.ring.activity.config.CallConfigActivity;
import com.bong.ring.activity.config.ConfigAlertActivity;
import com.bong.ring.activity.config.DisturbConfigActivity;
import com.bong.ring.activity.config.MessageConfigActivity;
import com.bong.ring.activity.config.SleepConfigActivity;
import com.bong.ring.activity.config.WatchConfigActivity;
import com.bong.ring.view.MenuItemView;


/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link TabFragmentMe.OnFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link TabFragmentMe#newInstance} factory method to
 * create an instance of this fragment.
 */
public class TabFragmentMe extends Fragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    private OnFragmentInteractionListener mListener;

    public TabFragmentMe() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment TabFragmentMe.
     */
    // TODO: Rename and change types and number of parameters
    public static TabFragmentMe newInstance(String param1, String param2) {
        TabFragmentMe fragment = new TabFragmentMe();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_me, container, false);
        LinearLayout linearLayout = view.findViewById(R.id.linear);
        (linearLayout).addView(new MenuItemView("设置",
                new String[]{"屏幕内容", "手势控制"},
                new int[]{R.mipmap.set_icon_1, R.mipmap.set_icon_2},
                getActivity()).setClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case 0:
                        startActivity(new Intent(getActivity(), WatchConfigActivity.class));
                        break;
                }
            }
        }).creat());
        (linearLayout).addView(new MenuItemView("运动健康",
                new String[]{"自动心率监测", "活动提醒", "睡眠提醒"},
                new int[]{R.mipmap.set_icon_3, R.mipmap.set_icon_4, R.mipmap.set_icon_5},
                getActivity()).setClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case 0:
                        startActivity(new Intent(getActivity(), AutoHeartConfigActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(getActivity(), ActivityConfigActivity.class));
                        break;
                    case 2:
                        startActivity(new Intent(getActivity(), SleepConfigActivity.class));
                        break;
                }
            }
        }).creat());
        (linearLayout).addView(new MenuItemView("生活助手",
                new String[]{"闹钟提醒", "消息提醒", "来电提醒", "勿扰模式", "寻找手环"},
                new int[]{R.mipmap.set_icon_6, R.mipmap.set_icon_7, R.mipmap.set_icon_8, R.mipmap.set_icon_9, R.mipmap.set_icon_10},
                getActivity()).setClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case 0:
                        startActivity(new Intent(getActivity(), ConfigAlertActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(getActivity(), MessageConfigActivity.class));
                        break;
                    case 2:
                        startActivity(new Intent(getActivity(), CallConfigActivity.class));
                        break;
                    case 3:
                        startActivity(new Intent(getActivity(), DisturbConfigActivity.class));
                        break;
                    case 4:
                        startActivity(new Intent(getActivity(), SearchActivity.class));
                        break;
                }
            }
        }).creat());
        return view;
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnFragmentInteractionListener) {
            mListener = (OnFragmentInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }
}
